#!/usr/bin/bash
#compile asm to hack
find . -name "*asm" | xargs -I {} echo {} | sed "s/^.\///" | xargs -I {} sh ../../tools/Assembler.sh {}
# compile asm to hack2
find . -name "*.asm" | xargs python3 ./translater.py

compare_files() {  
     file1="$1"  
     file2="$2"
     if [[ -f "$file1" ]] && [[ -f "$file2" ]]; then  
        echo diff $file1 $file2
        diff "$file1" "$file2"
     else  
       echo "One or both files not found."  
     fi  
}
# 查找文件夹中的所有 .asm 文件  
asm_files=$(find . -type f -name "*.asm")
# 对于每个 .asm 文件，找到对应的 .hack 和 .hack2 文件，并进行比较  
for asm_file in $asm_files; do  
    asm_file=$(echo $asm_file | sed 's/.asm$//')
    hack_file="$asm_file.hack"
    hack2_file="$asm_file.hack2"
    if [[ -f "$hack_file" ]] && [[ -f "$hack2_file" ]]; then
        compare_files "$hack_file" "$hack2_file"
    else
        echo "One or both hack files not found for" "$hack_file" "$hack2_file"
    fi
done
echo "If no thing echod, no diff."
